package com.huazai.rabbitmq.config.exchange;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitTopicConfig {

    public static final String TOPIC_QUEUE_ONE = "topicQueue-One";
    public static final String TOPIC_QUEUE_TWO = "topicQueue-Two";
    public static final String TOPIC_EX = "Topic-Ex";
    public static final String ROUTING_KEY_XIN = "*.Two.*";
    public static final String ROUTING_KEY_JING = "#";

    @Bean
    public Queue topicQueue(){
        //参数介绍
        //1.队列名 2.是否持久化 3.是否独占 4.自动删除 5.其他参数
        return new Queue(TOPIC_QUEUE_ONE,true,false,false,null);
    }

    @Bean
    public Queue topicQueue2(){
        //参数介绍
        //1.队列名 2.是否持久化 3.是否独占 4.自动删除 5.其他参数
        return new Queue(TOPIC_QUEUE_TWO,true,false,false,null);
    }

    @Bean
    public TopicExchange topicExchange(){
        //参数介绍
        //1.交换器名 2.是否持久化 3.自动删除 4.其他参数
        return new TopicExchange(TOPIC_EX,true,false,null);
    }

    @Bean
    public Binding topicBingExchange(){
        return BindingBuilder.bind(topicQueue())   //绑定队列
                .to(topicExchange())       //队列绑定到哪个交换器
                .with(ROUTING_KEY_XIN);        //路由key,必须指定
    }

    @Bean
    public Binding topicBingExchange2(){
        return BindingBuilder.bind(topicQueue2())   //绑定队列
                .to(topicExchange())       //队列绑定到哪个交换器
                .with(ROUTING_KEY_JING);         //路由key,必须指定
    }
}

